/*
 * Copyright (c) 2013-2015 Charkey. All rights reserved.
 *
 * This software is the confidential and proprietary information of Charkey.
 * You shall not disclose such Confidential Information and shall use it only
 * in accordance with the terms of the agreements you entered into with Charkey.
 *
 * Charkey MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE SOFTWARE,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
 *
 * Charkey SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING,
 * MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
 */

package cn.simastudio.talos.core.utils;

import cn.simastudio.talos.core.enums.OrganizationStatus;
import cn.simastudio.talos.core.model.base.Organization;
import cn.simastudio.talos.core.model.page.ZTreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * Usage: Organization（数据库模型）到ZTreeNode的转换工具类
 *
 * @author Charkey
 * @date 2015/7/10 21:11
 */
public class OrganizationConverter {

    /**
     * 将Organization对象转换为ZTree
     *
     * @param source List<Organization>
     * @return List<ZTreeNode>
     */
    public static List<ZTreeNode> toZTreeNode(List<Organization> source) {
        List<ZTreeNode> zTreeNodeList = new ArrayList<ZTreeNode>();
        for (Organization org : source) {
            ZTreeNode zTreeNode = new ZTreeNode();
            zTreeNode.setId(org.getId());
            zTreeNode.setpId(org.getParentId());
            zTreeNode.setName(org.getName());
            zTreeNode.setOpen(org.getParentId() == 0);
            zTreeNode.setParentId(org.getParentId());
            zTreeNode.setParentIds(org.getParentIds());
            zTreeNode.setAvailable(org.getStatus().equals(OrganizationStatus.Available.getValue()));
            zTreeNodeList.add(zTreeNode);
        }
        return zTreeNodeList;
    }

}
